package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.AddCouponBo;
import com.cskaoyan.bean.bo.BaseParamBo;
import com.cskaoyan.bean.bo.CouponBo;
import com.cskaoyan.bean.bo.UpdateCouponBo;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.CouponVo;
import com.cskaoyan.service.PromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/coupon")
public class CouponController {
    @Autowired
    PromotionService promotionService;

    @GetMapping("list")
    public BaseRespVo list(String name, Short type, Short status, BaseParamBo paramBo){
        BasePageData pageData = promotionService.getCuList(name,type,status,paramBo);
        return BaseRespVo.ok(pageData);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody CouponBo couponBo){
        promotionService.deleteCu(couponBo);
        return BaseRespVo.ok();
    }

    @GetMapping("read")
    public BaseRespVo read(Integer id){
        CouponVo couponVo = promotionService.getCuById(id);
        return BaseRespVo.ok(couponVo);
    }

    @GetMapping("listuser")
    public BaseRespVo listUser(Integer couponId, Integer userId, Short status, BaseParamBo paramBo){
        BasePageData basePageData = promotionService.getListUser(couponId,userId,status,paramBo);
        return BaseRespVo.ok(basePageData);
    }

    @PostMapping("update")
    public BaseRespVo updateCoupon(@RequestBody UpdateCouponBo updateCouponBo){
        CouponVo couponVo = promotionService.updateCoupon(updateCouponBo);
        if(couponVo == null){
            return BaseRespVo.fail("请继续修改!");
        }
        return BaseRespVo.ok(couponVo);
    }

    @PostMapping("create")
    public BaseRespVo createCoupon(@RequestBody AddCouponBo addCouponBo){
        CouponVo couponVo = promotionService.addCoupon(addCouponBo);
        if(couponVo == null){
            return BaseRespVo.fail("添加失败!");
        }
        return BaseRespVo.ok(couponVo);
    }
}
